﻿namespace Way.Bus.WMS.ST.Model
{
    using Way.Contract.MVC;
    using System;
    using System.Collections.Generic;
    using System.Runtime.CompilerServices;
    using Way.Bus.Model;
    using Way.EAP.DataAccess.Entity;
    using Way.Bus.WMS.Model;

    [EntityClassAttribut("ST_PackList", "派车运输单", IsOnAppendProperty=true)]
    public class ST_PackList : BasicInfo, IPropertyValueType
    {
        /// <summary>
        /// 仓库
        /// </summary>
        [EntityControl("仓库", false, true, 7)]
        [EntityForeignKey(typeof(WareHouse), "ID", "WAREHOUSENAME")]
        [EntityField(255)]
        public int TOWHNO { get; set; }

        private HierarchicalEntityView<ST_PackList, TransportCoordinates> _coordinatesList;
        private HierarchicalEntityView<ST_PackList, ST_OutNotice> _PackListNotice;

        public PropertyValueType[] GetValueType(ValueTypeArgs valueArgs)
        {
            string tn = this.ToString();
            List<PropertyValueType> list = new List<PropertyValueType>();
            if (valueArgs.ColumnName == "State" && valueArgs.TableName == tn)
            {
                PropertyValueType item = new PropertyValueType
                {
                    Text = "未装车",
                    Value = "0"
                };
                PropertyValueType type2 = new PropertyValueType
                {
                    Text = "装车中",
                    Value = "1"
                };
                PropertyValueType type5 = new PropertyValueType
                {
                    Text = "装车完成",
                    Value = "2"
                };
                PropertyValueType type3 = new PropertyValueType
                {
                    Text = "运输中",
                    Value = "3"
                };
                PropertyValueType type4 = new PropertyValueType
                {
                    Text = "运输完成",
                    Value = "4"
                };
                list.Add(item);
                list.Add(type2);
                list.Add(type5);
                list.Add(type3);
                list.Add(type4);
            }
            return list.ToArray();
        }

        [EntityControl("司机", false, true, 1), EntityForeignKey(typeof(ST_CarList), "ID", "WorkName"), EntityField(100)]
        public string TheDriver { get; set; }
        [EntityControl("车牌号", false, true, 2), EntityField(100)]
        public string CarNo { get; set; }

       

        [EntityControl("装车日期", true, true, 1), EntityField(100)]
        public DateTime PackDate { get; set; }

        [HierarchicalEntityControl(isadd=false, isedit=false, isselect=true, c="Way.Bus.WMS.ST.Controllers.OutOrder.ST_OutReceiptController")]
        public HierarchicalEntityView<ST_PackList, ST_OutNotice> PackListNotice
        {
            get
            {
                if (this._PackListNotice == null)
                {
                    this._PackListNotice = new HierarchicalEntityView<ST_PackList, ST_OutNotice>(this);
                   // this._PackListNotice.IsAssociateDelete = false;
                    this._PackListNotice.EntityDeleteToDataBase += new EntityDeleteToDataBaseHandler(_PackListNotice_EntityDeleteToDataBase);
                }
                return this._PackListNotice;
            }
        }
        [HierarchicalEntityControl(visible = true, disabled = true)]
        public HierarchicalEntityView<ST_PackList, TransportCoordinates> CoordinatesList
        {
            get
            {
                if (this._coordinatesList == null)
                {
                    this._coordinatesList = new HierarchicalEntityView<ST_PackList, TransportCoordinates>(this);
                }
                return this._coordinatesList;
            }
        }
        void _PackListNotice_EntityDeleteToDataBase(ListEventArgs e)
        {
            string sql = "update " + e.ObjectBase.ToString() + " set packid=0 where id=" + e.ObjectBase["id"];
            e.Action.Execute(sql);
            e.IsContin = false;
        }

        [EntityControl("电话", false, true, 3), EntityField(100)]
        public string Phone { get; set; }

        [EntityField(10), EntityControl("状态", true, true, 1), ValueTypeProperty]
        public int State { get; set; }

    }
}

